home *** CD-ROM | disk | FTP | other *** search
- /*****
- * thermWindow.c
- *
- * The window routines for the Thermometer™
- *
- * Copyright © 1991-1992 Bernard Bernstein. All rights reserved.
- *****/
-
- #include <Color.h>
- #include "thermo.h"
-
- WindowPtr tempWindow;
- Rect dragRect;
- extern short temperature;
- extern thermPrefsRec thermPrefs;
- Rect thermRect;
-
- /****
- * SetUpWindow()
- *
- * Create the Thermometer window, and open it.
- *
- ****/
- SetUpWindow()
- {
- dragRect = screenBits.bounds;
-
- tempWindow = GetNewWindow(WINDMain, 0L, -1L);
-
- SetPort(tempWindow);
-
- ComputeThermRect();
- }
- /* end SetUpWindow */
-
- /***
- * UpdateWindowTitle
- *
- * Set the window title to C or F
- ***/
- UpdateWindowTitle()
- {
- Str255 winTitle;
-
- if (thermPrefs.scale == farenheit)
- GetIndString(&winTitle, STRScales, STRFarenTitle);
- else
- GetIndString(&winTitle, STRScales, STRCelciTitle);
-
- SetWTitle(tempWindow, winTitle);
- }
-
-
-
- /***
- * ComputeThermRect
- *
- * What rect is the mercury in?
- ***/
- ComputeThermRect()
- {
- GrafPtr savePort;
- GetPort(&savePort);
- SetPort(tempWindow);
-
- thermRect = tempWindow->portRect;
- thermRect.top += 5;
- thermRect.bottom -= 20;
- thermRect.right -= 5;
- thermRect.left = thermRect.right - 10;
- SetPort(savePort);
- }
-
- /***
- * DoWindowClick
- *
- * Window was clicked. Grow the window if in grow box
- ***/
- DoWindowClick(Point mousePt)
- {
- long newPt;
- Rect sizeRect;
- short w,h;
- Point thermBR, thermTL;
- Rect devRect;
- GDHandle saveDev;
- GDHandle thisDev;
-
-
- thermBR = botRight(thermRect);
- thermTL = topLeft(thermRect);
- LocalToGlobal(&thermTL);
- LocalToGlobal(&thermBR);
- if (mousePt.v > thermBR.v) {
- sizeRect = tempWindow->portRect;
- sizeRect.left = sizeRect.right += 1;
- sizeRect.top = 50;
- saveDev = GetGDevice();
- thisDev = GetDeviceList();
- while (thisDev != 0L) {
- devRect = (**thisDev).gdRect;
- if (PtInRect(thermTL, &devRect)) {
- sizeRect.bottom = devRect.bottom - devRect.top;
- }
- thisDev = GetNextDevice(thisDev);
- }
- SetGDevice(saveDev);
- newPt = GrowWindow(tempWindow, mousePt, &sizeRect);
- if (newPt != 0L) {
- h = HiWord(newPt);
- w = LoWord(newPt);
- SizeWindow(tempWindow,w,h,FALSE);
- ComputeThermRect();
- }
- InvalRect(&tempWindow->portRect);
- }
- }
-
- /*****
- * DrawTempWindow
- *
- * Draws the temperature window.
- *
- *****/
- DrawTempWindow(active)
-
- short active;
-
- {
- GrafPtr savePort;
- short i;
- Rect frame;
- short height,width;
- short min, max, range;
- float interval;
- short linev;
- Str255 numStr;
- Rect merc;
- short adjustedTemp;
- Rect well;
-
- GetPort(&savePort);
- SetPort(tempWindow);
-
- frame = tempWindow->portRect;
- height = thermRect.bottom - thermRect.top;
-
- EraseRect(&frame);
-
- min = thermPrefs.min;
- max = thermPrefs.max;
- range = max - min;
- interval = (float)height / range;
-
- adjustedTemp = (temperature - min) * interval;
- if (adjustedTemp > height)
- adjustedTemp = height;
- else if (adjustedTemp < 0)
- adjustedTemp = 0;
-
- FrameRect(&thermRect);
-
- well = thermRect;
- well.right += 4;
- well.left -= 4;
- well.top = well.bottom;
- well.bottom = frame.bottom;
- FrameRoundRect(&well, 8, 8);
- FillRoundRect(&well, 8, 8, dkGray);
-
- merc = thermRect;
- merc.top = merc.bottom - adjustedTemp;
- FillRect(&merc, dkGray);
-
- TextSize(9);
- PenMode(patXor);
- for (i=min; i<max; i++) {
- if (i % 10 == 0) {
- linev = thermRect.bottom - ((i-min) * interval);
-
- MoveTo(frame.left, linev);
- LineTo(thermRect.left - 1, linev);
- MoveTo(thermRect.right, linev);
- LineTo(frame.right, linev);
-
- MoveTo(frame.left + 2, linev);
- NumToString((long)i, &numStr);
- DrawString(numStr);
- } else if (interval > 2) {
- if (i % 2 == 0) {
- linev = thermRect.bottom - ((i-min) * interval);
- MoveTo(thermRect.left - 3, linev);
- LineTo(thermRect.left - 1, linev);
- MoveTo(thermRect.right, linev);
- LineTo(thermRect.right + 3, linev);
- }
- } else if (interval > 1) {
- if (i % 5 == 0) {
- linev = thermRect.bottom - ((i-min) * interval);
- MoveTo(thermRect.left - 3, linev);
- LineTo(thermRect.left - 1, linev);
- MoveTo(thermRect.right, linev);
- LineTo(thermRect.right + 3, linev);
- }
- }
- }
-
- merc = thermRect;
- merc.top = merc.bottom - (temperature - min) * interval;
- FillRect(&merc, dkGray);
-
- SetPort(savePort);
- }
- /* end DrawTempWndow */
-